package Graphic;


import businessLogic.PlayerActions;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.Serializable;
import java.util.ArrayList;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import scala40rules.*;


/**
 *
 * @author macbook
 */

public class DraftLayout extends javax.swing.JFrame implements Serializable{
    /**
	 *
	 */
	private static final long serialVersionUID = 1L;

    //variabili di classe
    private JButton button_scala, button_validate, button_delBaloon, button_passaTurno;
    //private JButton card1_button, card2_button, card3_button, card4_button, card5_button, card6_button, card7_button, card8_button, card9_button,card10_button,card11_button,card12_button,card13_button,card14_button;
    CursorOverHands c;
    CardOnHands cardOver=new CardOnHands();
    CardsCombinations cardsCombinations=new CardsCombinations();
    FlowLayout experimentLayout = new FlowLayout();
    static int numberOfRows;
    static int currentLine;
    JPopupMenu popupMenu = new JPopupMenu();
    JPopupMenu popupMenuButton = new JPopupMenu();
    JPopupMenu popupMenuButton2 = new JPopupMenu();
    ArrayList<Boolean> visible=new ArrayList<Boolean>();
    PlayerActions playerActions;
    Card discardCard =new Card();
    ImageIcon vuota=new ImageIcon("src/small_cards/carta_vuota.png");
    ImageIcon scala=new ImageIcon("src/small_cards/scala.png");
    ImageIcon addNewLine=new ImageIcon("src/small_cards/baloon.png");
    ImageIcon deleteBaloon=new ImageIcon("src/small_cards/delete.png");
    final JButton scopertaButton=new JButton(vuota);
    static int positionCartForAttach=-1;
    static boolean myTurn=false;

    //
        private javax.swing.JLabel labelTurn;
    private javax.swing.JPanel panelCommand;
    private javax.swing.JPanel panelDeck;
    private javax.swing.JPanel panelMyTurn;
    private javax.swing.JInternalFrame jInternalFrame1;
    JLabel labelStat=new JLabel();

    //creare  carte
    Card card1=new Card(1,"asso_cuori", "abla",true, "src/cards/asso_cuori.png","src/small_cards/asso_cuori.png");
    Card card2=new Card(2,"due_cuori", "abla",true, "src/cards/due_cuori.png","src/small_cards/due_cuori.png");
    Card card3=new Card(11,"jack_cuori", "abla",true, "src/cards/jack_cuori.png","src/small_cards/jack_cuori.png");
//    Card card4=new Card(3,"tre_cuori", "abla",true, "src/cards/tre_cuori.png","src/small_cards/tre_cuori.png");
//    Card card5=new Card(12,"donna_fiori", "abla",true, "src/cards/donna_fiori.png","src/small_cards/donna_fiori.png");
//    Card card6=new Card(1,"asso_quadri", "abla",true, "src/cards/asso_quadri.png","src/small_cards/asso_quadri.png");
//    Card card7=new Card(2,"due_quadri", "abla",true, "src/cards/due_quadri.png","src/small_cards/due_quadri.png");
//    Card card8=new Card(3,"tre_quadri", "abla",true, "src/cards/tre_quadri.png","src/small_cards/tre_quadri.png");
//    Card card9=new Card(4,"quattro_quadri", "abla",true, "src/cards/quattro_quadri.png","src/small_cards/quattro_quadri.png");
//    Card card10=new Card(8,"otto_picche", "abla",true, "src/cards/otto_picche.png","src/small_cards/otto_picche.png");
//    Card card11=new Card(9,"nove_picche", "abla",true, "src/cards/nove_picche.png","src/small_cards/nove_picche.png");
//    Card card12=new Card(11,"jack_picche", "abla",true, "src/cards/jack_picche.png","src/small_cards/jack_picche.png");
//    Card card13=new Card(1,"asso_fiori", "abla",true, "src/cards/asso_fiori.png","src/small_cards/asso_fiori.png");
//    Card card14=new Card();//new Card(2,"due_fiori", "abla",true, "src/cards/due_fiori.png","src/small_cards/due_fiori.png");
  


    //vettore delle carte in mano
    CardSet cards_on_hands= new CardSet();
    
//    private static final DraftLayout DRAFTLAYOUT_INSTANCE = new DraftLayout();
    
/*
    Image img1 = Toolkit.getDefaultToolkit().getImage("src/cards/asso_cuori.png");
    Image img2 = Toolkit.getDefaultToolkit().getImage("src/cards/asso_fiori.png");
    Image img3 = Toolkit.getDefaultToolkit().getImage("src/cards/asso_quadri.png");
    Image img4 = Toolkit.getDefaultToolkit().getImage("src/cards/asso_picche.png");
    Image img5 = Toolkit.getDefaultToolkit().getImage("src/cards/donna_picche.png");
    Image img6 = Toolkit.getDefaultToolkit().getImage("src/cards/donna_cuori.png");
*/
    //ImageIcon icon = new ImageIcon("src/cards/asso_cuori.png");

    //ImageIcon icon_small = new ImageIcon("src/small_cards/asso_cuori.png");

    JInternalFrame cardsOnHand = new javax.swing.JInternalFrame("Cards On Hand");
    JInternalFrame container_buttons = new javax.swing.JInternalFrame("Actions");

    ArrayList<PositionArea> vettore=new ArrayList<PositionArea>();
    //ArrayList<Punti> vettore=new ArrayList<Punti>();
    ArrayList<Image> vettoreImage=new ArrayList<Image>();

    
    //vettore di pulsanti
    ArrayList<JButton> arrayButton=new ArrayList<JButton>();
    private JButton button_inv1;

    //fine variabili di classe

    //vettore delle carte che il giocatore ha in mano
   // ArrayList<Image> vettoreCarteInMano=new ArrayList<Image>();


    /** Creates new form NuovaForm */
    public DraftLayout() {

           cards_on_hands.addCard(new Card());cards_on_hands.addCard(new Card());cards_on_hands.addCard(new Card());
           cards_on_hands.addCard(new Card());cards_on_hands.addCard(new Card());cards_on_hands.addCard(new Card());
           cards_on_hands.addCard(new Card());cards_on_hands.addCard(new Card());cards_on_hands.addCard(new Card());
           cards_on_hands.addCard(new Card());cards_on_hands.addCard(new Card());cards_on_hands.addCard(new Card());
           cards_on_hands.addCard(new Card());cards_on_hands.addCard(new Card());

           
         //inizializzo carte
           for(int i=0;i<14;i++){
               arrayButton.add(new JButton(cards_on_hands.getCard(i).getIcon()));
               arrayButton.get(i).setMargin(new Insets(0,0,0,0));
           }
           

           for(int i=0;i<cards_on_hands.size();i++){
            if(cards_on_hands.getCard(i).getSymbol()==null){
                //arrayButton.get(i).setVisible(false);
            }
        }

        numberOfRows=1;
        currentLine=0;

        initComponents();
       
       
       

    }


//    public static synchronized DraftLayout getInstance(){
//		return DRAFTLAYOUT_INSTANCE;
//	}
    


    @SuppressWarnings("unchecked")
    public void initComponents(){

        c=new CursorOverHands();

        final CardSet cards= new CardSet();
        cards.addCard(card1);cards.addCard(card2);cards.addCard(card3);

       //c.updateBoxOccupied(19);
        
        //setBackground(Color.decode("#006400"));
        Container cont=this.getContentPane();
        cont.setBackground(Color.decode("#006400"));

        //creo il mazzo di carte in mano
        /*
            cards_on_hands.add(card1);cards_on_hands.add(card2);cards_on_hands.add(card3);
            cards_on_hands.add(card4);cards_on_hands.add(card5);cards_on_hands.add(card6);
            cards_on_hands.add(card7);cards_on_hands.add(card8);cards_on_hands.add(card9);
            cards_on_hands.add(card10);cards_on_hands.add(card11);cards_on_hands.add(card12);
            cards_on_hands.add(card13);cards_on_hands.add(card14);
        */
       

        
            

        //creazione Frame interno di rappresentazione tavolo
        MyInternalFrame cardOnTable = new MyInternalFrame("Cards On The Table",1,1,1050,570);
        cardOnTable.getContentPane().add(c);
        cardOnTable.setMaximizable(false);
        // cardOnTable.setLocationRelativeTo(null);
        cardOnTable.setVisible(true);
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        InitialPositionVector();


        

        MyInternalFrame carteInMano = new MyInternalFrame("Cards On Hand",1,1,500,500);
        carteInMano.getContentPane().add(cardOver);
        carteInMano.setMaximizable(false);
        carteInMano.setVisible(true);
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);


        final MyInternalFrame think = new MyInternalFrame("Baloon",1,1,500,500);
        think.getContentPane().add(cardsCombinations);
        think.setMaximizable(false);
       // think.getContentPane().add(cardOver);
        think.setVisible(true);
        
       

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

//        button_attacca = new JButton("     Attacca     ");
//        button_scala = new JButton("       Scala       ");
//        button_validate = new JButton(" Add New Line  ");


       // button_attacca = new JButton("     Attacca     ");
        button_scala = new JButton(scala);//"Scala");
        button_validate = new JButton(addNewLine);//"Add line");

        button_delBaloon = new JButton(deleteBaloon);//"Del Ball");
        button_passaTurno = new JButton("Passa");

        button_inv1 = new JButton("AA");
        button_inv1.setVisible(false);

        //inizializzo vettore visible
        for(int i=0;i<14;i++){
            visible.add(true);
        }


        

/*
        card1_button = new JButton(cards_on_hands.getCard(0).getIcon());card2_button = new JButton(cards_on_hands.getCard(1).getIcon());card3_button = new JButton(cards_on_hands.getCard(2).getIcon());card4_button = new JButton(cards_on_hands.getCard(3).getIcon());
        card5_button = new JButton(cards_on_hands.getCard(4).getIcon());card6_button = new JButton(cards_on_hands.getCard(5).getIcon());card7_button = new JButton(cards_on_hands.getCard(6).getIcon());card8_button = new JButton(cards_on_hands.getCard(7).getIcon());
        card9_button = new JButton(cards_on_hands.getCard(8).getIcon());card10_button = new JButton(cards_on_hands.getCard(9).getIcon());card11_button = new JButton(cards_on_hands.getCard(10).getIcon());card12_button = new JButton(cards_on_hands.getCard(11).getIcon());
        card13_button = new JButton(cards_on_hands.getCard(12).getIcon());card14_button = new JButton(cards_on_hands.getCard(13).getIcon());
        //button_scala.setText("button_scala");
*/

        //inizializzo vettore carte in mano
        /*
        vettoreCarteInMano.add(img1);vettoreCarteInMano.add(img2);vettoreCarteInMano.add(img3);
        vettoreCarteInMano.add(img4);vettoreCarteInMano.add(img5);vettoreCarteInMano.add(img6);
        vettoreCarteInMano.add(img1);vettoreCarteInMano.add(img2);vettoreCarteInMano.add(img2);
        vettoreCarteInMano.add(img3);vettoreCarteInMano.add(img4);vettoreCarteInMano.add(img5);
        vettoreCarteInMano.add(img6);vettoreCarteInMano.add(img1);*/
//        JMenuItem cutMenuItemDel = new JMenuItem("Cancels 1° row");
//        popupMenu.add(cutMenuItemDel);

        //actionListener tasto destro mouse per cancellare da think
        //final PopupMenuDelete p=new PopupMenuDelete();
        final ActionListener actionListener = new ActionListener() {
            public void actionPerformed(ActionEvent actionEvent) {
                String simbol;
                //gestioe evento
                CardSet tempCardSet=new CardSet();
                if(actionEvent.getActionCommand().equals("Cancels 1° row")){

                    //gestione popup
                    System.out.println("VALORE numberOfRows: "+numberOfRows);
                    numberOfRows--;
                    switch(numberOfRows){
                        case 1:
                                popupMenu.remove(1);break;
                        case 2:
                                popupMenu.remove(2);break;
                   
                        case 3:
                                popupMenu.remove(3);break;
                                
                        case 4:
                                popupMenu.remove(4);break;
                                
                   }

                   currentLine--;
                   //numberOfRows--;
                   //System.out.println("contenuto POPUP: "+popupMenu.toString());


                    //stampa simboli di think
                    System.out.println("Beccato opz 1");
                    tempCardSet=cardsCombinations.removeGroup(0);

                     for(int i=0;i<tempCardSet.size();i++){
                         if(tempCardSet.getCard(i)!=null){
                         System.out.println("Simboli ritornati: "+tempCardSet.getCard(i).getSymbol());
                         }
                     }

                     playerActions.removeLevelFromBaloon(0);
                     playerActions.addLineToBaloon();
                     cardsCombinations.decreaseIndexLine();
                /*    int position;
                    for(int i=0;i<tempCardSet.size();i++){
                        if(tempCardSet.getCard(i)!=null){
                        simbol=tempCardSet.getCard(i).getSymbol();

                        position=foundIndex(simbol);
                        
                        arrayButton.get(position).setVisible(true);
                        }
                    }*/
  
                }
                if(actionEvent.getActionCommand().equals("Cancels 2° row")){

                    //gestione popup
                    System.out.println("VALORE numberOfRows: "+numberOfRows);
                    numberOfRows--;
                    switch(numberOfRows){
                        case 1:
                                popupMenu.remove(1);break;
                        case 2:
                                popupMenu.remove(2);break;

                        case 3:
                                popupMenu.remove(3);break;

                        case 4:
                                popupMenu.remove(4);break;

                   }
                   currentLine--;
                   //numberOfRows--;
                    System.out.println("Beccato opz 2");
                    tempCardSet=cardsCombinations.removeGroup(1);
                    
                    for(int i=0;i<tempCardSet.size();i++){
                         if(tempCardSet.getCard(i)!=null){
                         System.out.println("Simboli ritornati: "+tempCardSet.getCard(i).getSymbol());
                         }
                     }

                    playerActions.removeLevelFromBaloon(1);
                    playerActions.addLineToBaloon();
                    cardsCombinations.decreaseIndexLine();
                    /*

                    int position;
                    for(int i=0;i<tempCardSet.size();i++){
                        if(tempCardSet.getCard(i)!=null){
                        simbol=tempCardSet.getCard(i).getSymbol();

                        position=foundIndex(simbol);

                        arrayButton.get(position).setVisible(true);
                        }
                    }*/
                   
                }
                if(actionEvent.getActionCommand().equals("Cancels 3° row")){

                    //gestione popup
                    System.out.println("VALORE numberOfRows: "+numberOfRows);
                    numberOfRows--;
                    switch(numberOfRows){
                        case 1:
                                popupMenu.remove(1);break;
                        case 2:
                                popupMenu.remove(2);break;

                        case 3:
                                popupMenu.remove(3);break;

                        case 4:
                                popupMenu.remove(4);break;

                   }
                   currentLine--;
                   //numberOfRows--;
                    System.out.println("Beccato opz 3");
                    tempCardSet=cardsCombinations.removeGroup(2);
                    for(int i=0;i<tempCardSet.size();i++){
                         if(tempCardSet.getCard(i)!=null){
                         System.out.println("Simboli ritornati: "+tempCardSet.getCard(i).getSymbol());
                         }
                     }

                    playerActions.removeLevelFromBaloon(2);
                    playerActions.addLineToBaloon();
                    cardsCombinations.decreaseIndexLine();
                    /*
                    int position;
                    for(int i=0;i<tempCardSet.size();i++){
                        if(tempCardSet.getCard(i)!=null){
                        simbol=tempCardSet.getCard(i).getSymbol();

                        position=foundIndex(simbol);

                        arrayButton.get(position).setVisible(true);
                        }
                    }*/
                    
                }
                if(actionEvent.getActionCommand().equals("Cancels 4° row")){

                    //gestione popup
                    System.out.println("VALORE numberOfRows: "+numberOfRows);
                    numberOfRows--;
                    switch(numberOfRows){
                        case 1:
                                popupMenu.remove(1);break;
                        case 2:
                                popupMenu.remove(2);break;

                        case 3:
                                popupMenu.remove(3);break;

                        case 4:
                                popupMenu.remove(4);break;

                   }
                   //numberOfRows--;
                    currentLine--;
                    System.out.println("Beccato opz 4");
                    tempCardSet=cardsCombinations.removeGroup(3);
                    for(int i=0;i<tempCardSet.size();i++){
                         if(tempCardSet.getCard(i)!=null){
                         System.out.println("Simboli ritornati: "+tempCardSet.getCard(i).getSymbol());
                         }
                     }

                    playerActions.removeLevelFromBaloon(3);
                    playerActions.addLineToBaloon();
                    cardsCombinations.decreaseIndexLine();
                    /*
                    int position;
                    for(int i=0;i<tempCardSet.size();i++){
                        if(tempCardSet.getCard(i)!=null){
                        simbol=tempCardSet.getCard(i).getSymbol();

                        position=foundIndex(simbol);

                        arrayButton.get(position).setVisible(true);
                        }
                    }*/
                    
                    
                    
                }

                if(actionEvent.getActionCommand().equals("Delete current line")){
                    
                    //gestione popup
                    System.out.println("VALORE numberOfRows: "+numberOfRows);
                    //ritorna la riga corrente che sto inserendo
                    //int indexDel=playerActions.getLastBaloonLineNumber();
//                    System.out.println("VALORE indexDel: "+indexDel);
                   
                    System.out.println("Current Line: "+currentLine);
                    //cancello tutti gli elementi di quella riga
                    
                    
                    cardsCombinations.removeGroup(currentLine);
                    playerActions.removeLevelFromBaloon(currentLine);
                    playerActions.addLineToBaloon();
                    //numberOfRows--;


                   
                    /*

                    int position;
                    for(int i=0;i<tempCardSet.size();i++){
                        if(tempCardSet.getCard(i)!=null){
                        simbol=tempCardSet.getCard(i).getSymbol();

                        position=foundIndex(simbol);

                        arrayButton.get(position).setVisible(true);
                        }
                    }*/

                }
                //System.out.println("Selected: "+ actionEvent.getActionCommand());
            }
        };
       /* PopupMenuListener popupMenuListener = new PopupMenuListener() {
            public void popupMenuCanceled(PopupMenuEvent popupMenuEvent) { }

            public void popupMenuWillBecomeInvisible(
                PopupMenuEvent popupMenuEvent) { }

            public void popupMenuWillBecomeVisible(PopupMenuEvent popupMenuEvent) { }
        };*/

        
        //   popupMenu.addPopupMenuListener(popupMenuListener);



        //imposto la prima riga corrente come subito cancellabile prima di validare qualsiasi cosa
        JMenuItem cutMenuItem = new JMenuItem("Delete current line");
        cutMenuItem.addActionListener(actionListener);
        popupMenu.add(cutMenuItem);








   /* JMenuItem copyMenuItem = new JMenuItem("Copy");
    copyMenuItem.addActionListener(actionListener);
    popupMenu.add(copyMenuItem);

    JMenuItem pasteMenuItem = new JMenuItem("Paste");
    pasteMenuItem.addActionListener(actionListener);
    pasteMenuItem.setEnabled(false);
    popupMenu.add(pasteMenuItem);*/
        MouseListener mouseListener = new PopupMenuShower(popupMenu);
        think.addMouseListener(mouseListener);


        think.addMouseListener(
            new MouseAdapter(){
                @Override
             public void mousePressed(MouseEvent e) {
              
               //catch tasto destro del mouse
               if (e.getButton() == MouseEvent.BUTTON3) {
               System.out.println("TASTO DESTRO CLICCATO.");
               System.out.println(e.isPopupTrigger());
               if (e.isPopupTrigger()) {
                    
                }
               
               System.out.println();
             }
        }});



        //aggiunta listenerButton
        button_scala.addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    if(isMyTurn()){
                        System.out.println("[DraftLayout || Scala listener]");

                    String result=playerActions.putDownBaloon();
                    System.out.println("valore di result: "+result);

                    if(result==""){

                    int dimThink=cardsCombinations.dimList();
                    System.out.println("!!!!!!!!!!!! "+playerActions.getBaloon().size()+"!!!!!!!!!!!!!!!!");
                    int numCardsetOnThink=playerActions.getBaloon().size();
                    switch(playerActions.getBaloon().size()){
                        case 0:
                                cardsCombinations.removeAll();
                                break;
                                //cancella tutto il pensiero;break;
                        case 1:
                                CardSet c=playerActions.getLastBaloonLine();
                                cardsCombinations.removeWithoutLast(c);
                                break;
                               //tenere solo ultima riga del pensiero;break;
                   }

                   draw();

/*
                    //immagini area 1
                    vettoreImage.add(card1.getImage());
                    vettoreImage.add(card2.getImage());
                    vettoreImage.add(card3.getImage());
                    vettoreImage.add(card4.getImage());
                    vettoreImage.add(card5.getImage());
                    vettoreImage.add(card1.getImage());
                    vettoreImage.add(card2.getImage());

                    //immagini area 2
                    vettoreImage.add(card1.getImage());
                    vettoreImage.add(card2.getImage());
                    vettoreImage.add(card3.getImage());
                    vettoreImage.add(card4.getImage());
                    vettoreImage.add(card5.getImage());
                    vettoreImage.add(card2.getImage());
                    vettoreImage.add(card3.getImage());

                    //immagini area 3
                    vettoreImage.add(card1.getImage());
                    vettoreImage.add(card2.getImage());
                    vettoreImage.add(card3.getImage());
                    vettoreImage.add(card4.getImage());
                    vettoreImage.add(card5.getImage());
                    vettoreImage.add(card6.getImage());
                    vettoreImage.add(card2.getImage());

                    //immagini area 4
                    vettoreImage.add(card1.getImage());
                    vettoreImage.add(card2.getImage());
                    vettoreImage.add(card3.getImage());
                    vettoreImage.add(card4.getImage());
                    vettoreImage.add(card5.getImage());
                    vettoreImage.add(card6.getImage());
                    vettoreImage.add(card3.getImage());

                    //immagini area 5
                    vettoreImage.add(card1.getImage());
                    vettoreImage.add(card2.getImage());
                    vettoreImage.add(card3.getImage());
                    vettoreImage.add(card4.getImage());
                    vettoreImage.add(card5.getImage());
                    vettoreImage.add(card6.getImage());
                    vettoreImage.add(card4.getImage());

                    //immagini area 6
                    vettoreImage.add(card1.getImage());
                    vettoreImage.add(card2.getImage());
                    vettoreImage.add(card3.getImage());
                    vettoreImage.add(card4.getImage());
                    vettoreImage.add(card5.getImage());
                    vettoreImage.add(card2.getImage());
                    vettoreImage.add(card1.getImage());

                    //immagini area 7
                    vettoreImage.add(card1.getImage());
                    vettoreImage.add(card2.getImage());
                    vettoreImage.add(card3.getImage());
                    vettoreImage.add(card4.getImage());
                    vettoreImage.add(card3.getImage());
                    vettoreImage.add(card2.getImage());
                    vettoreImage.add(card1.getImage());

                    //immagini area 8
                    vettoreImage.add(card1.getImage());
                    vettoreImage.add(card2.getImage());
                    vettoreImage.add(card3.getImage());
                    vettoreImage.add(card4.getImage());
                    vettoreImage.add(card1.getImage());
                    vettoreImage.add(card2.getImage());
                    vettoreImage.add(card4.getImage());

                    //immagini area 9
                    vettoreImage.add(card1.getImage());
                    vettoreImage.add(card2.getImage());
                    vettoreImage.add(card3.getImage());
                    vettoreImage.add(card4.getImage());
                    vettoreImage.add(card5.getImage());
                    vettoreImage.add(card6.getImage());
                    vettoreImage.add(card3.getImage());

                    //immagini area 10
                    vettoreImage.add(card1.getImage());
                    vettoreImage.add(card2.getImage());
                    vettoreImage.add(card3.getImage());
                    vettoreImage.add(card4.getImage());
                    vettoreImage.add(card5.getImage());
                    vettoreImage.add(card3.getImage());
                    vettoreImage.add(card5.getImage());

                    //immagini area 11
                    vettoreImage.add(card1.getImage());
                    vettoreImage.add(card2.getImage());
                    vettoreImage.add(card3.getImage());
                    vettoreImage.add(card4.getImage());
                    vettoreImage.add(card5.getImage());
                    vettoreImage.add(card2.getImage());
                    vettoreImage.add(card4.getImage());

                    //immagini area 12
                    vettoreImage.add(card1.getImage());
                    vettoreImage.add(card2.getImage());
                    vettoreImage.add(card3.getImage());
                    vettoreImage.add(card4.getImage());
                    vettoreImage.add(card5.getImage());
                    vettoreImage.add(card2.getImage());
                    vettoreImage.add(card3.getImage());

                    //immagini area 13
                    vettoreImage.add(card1.getImage());
                    vettoreImage.add(card2.getImage());
                    vettoreImage.add(card3.getImage());
                    vettoreImage.add(card4.getImage());
                    vettoreImage.add(card3.getImage());
                    vettoreImage.add(card4.getImage());
                    vettoreImage.add(card2.getImage());

                    //immagini area 14
                    vettoreImage.add(card1.getImage());
                    vettoreImage.add(card2.getImage());
                    vettoreImage.add(card3.getImage());
                    vettoreImage.add(card4.getImage());
                    vettoreImage.add(card3.getImage());
                    vettoreImage.add(card4.getImage());
                    vettoreImage.add(card2.getImage());

                    //immagini area 15
                    vettoreImage.add(card1.getImage());
                    vettoreImage.add(card2.getImage());
                    vettoreImage.add(card3.getImage());
                    vettoreImage.add(card4.getImage());
                    vettoreImage.add(card5.getImage());
                    vettoreImage.add(card2.getImage());
                    vettoreImage.add(card3.getImage());

                    //immagini area 16
                    vettoreImage.add(card1.getImage());
                    vettoreImage.add(card2.getImage());
                    vettoreImage.add(card3.getImage());
                    vettoreImage.add(card4.getImage());
                    vettoreImage.add(card5.getImage());
                    vettoreImage.add(card2.getImage());
                    vettoreImage.add(card3.getImage());

                    //immagini area 17
                    vettoreImage.add(card1.getImage());
                    vettoreImage.add(card2.getImage());
                    vettoreImage.add(card3.getImage());
                    vettoreImage.add(card4.getImage());
                    vettoreImage.add(card5.getImage());
                    vettoreImage.add(card4.getImage());
                    vettoreImage.add(card5.getImage());

                    //immagini area 18
                    vettoreImage.add(card1.getImage());
                    vettoreImage.add(card2.getImage());
                    vettoreImage.add(card3.getImage());
                    vettoreImage.add(card2.getImage());
                    vettoreImage.add(card3.getImage());
                    vettoreImage.add(card2.getImage());
                    vettoreImage.add(card3.getImage());

                    //immagini area 19
                    vettoreImage.add(card1.getImage());
                    vettoreImage.add(card2.getImage());
                    vettoreImage.add(card3.getImage());
                    vettoreImage.add(card4.getImage());
                    vettoreImage.add(card2.getImage());
                    vettoreImage.add(card3.getImage());
                    vettoreImage.add(card4.getImage());

                    //immagini area 20
                    vettoreImage.add(card1.getImage());
                    vettoreImage.add(card2.getImage());
                    vettoreImage.add(card3.getImage());
                    vettoreImage.add(card4.getImage());
                    vettoreImage.add(card5.getImage());
                    vettoreImage.add(card4.getImage());
                    vettoreImage.add(card5.getImage());

*/



//                    ChoiseValueJoker joker=new ChoiseValueJoker();
//                    joker.setBounds(100, 140, 140, 500);
//                    joker.setVisible(true);
//                    joker.message(cards);



                    //risetto gli indici iniziali di posizionamento del baloon
                    numberOfRows=1;
                    currentLine=0;

                    //inserire il nuemero di cardset del pensiero da scalare
                    c.updateBoxOccupied(playerActions.getCardsOnTheTable().size()-1);
                    System.out.println("Numero di posizioni da aggiornare: "+(playerActions.getCardsOnTheTable().size()-1));


                    }else{
                        DialogBox d=new DialogBox();
                        d.message(result);
                    }
                    
                    }
                    else{
                        //non è il turno
                        DialogBox d=new DialogBox();
                        d.message("Non è possibile scalare. Non è il tuo turno");
                    }
                }
            }
        );


        JPanel panel1=new JPanel();

 /*************************************************** test panel 1*******************************/

       //prima era new BoxLayout(panel1, BoxLayout.PAGE_AXIS)
       panel1.setLayout(new GridLayout(12,1,0,-20));



       

      // panel1.add(button_validate,BorderLayout.PAGE_END);
      // panel1.add(button_delBaloon,BorderLayout.CENTER);
       
      // panel1.add(button_attacca,BorderLayout.PAGE_END);

     //  panel1.add(button_scala,BorderLayout.CENTER);


       ImageIcon dorso=new ImageIcon("src/small_cards/dorso_rosso.png");
       JButton dorsoButton=new JButton(dorso);
       dorsoButton.setMargin(new Insets(0,0,0,0));
    //   panel1.add(dorsoButton,BorderLayout.CENTER);
       
       
      // panel1.add(scopertaButton,BorderLayout.CENTER);

      // panel1.add(button_passaTurno,BorderLayout.CENTER);

      panelDeck = new javax.swing.JPanel();
      panelCommand = new javax.swing.JPanel();
      panelMyTurn = new javax.swing.JPanel();
      labelTurn = new javax.swing.JLabel(new ImageIcon("src/small_cards/no.png"));
      scopertaButton.setMargin(new Insets(0,0,0,0));
      jInternalFrame1 = new javax.swing.JInternalFrame();

//      jInternalFrame1.setTitle("Acs");
//      jInternalFrame1.setVisible(true);

        panelDeck.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "deck of cards", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("SansSerif", 1, 12))); // NOI18N





        org.jdesktop.layout.GroupLayout panelDeckLayout = new org.jdesktop.layout.GroupLayout(panelDeck);
        panelDeck.setLayout(panelDeckLayout);
        panelDeckLayout.setHorizontalGroup(
            panelDeckLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER)
            .add(panelDeckLayout.createSequentialGroup()
                .add(dorsoButton)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(scopertaButton))
        );
        panelDeckLayout.setVerticalGroup(
            panelDeckLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, panelDeckLayout.createSequentialGroup()
                .addContainerGap()
                .add(panelDeckLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(scopertaButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(dorsoButton)))
                //.add(67, 67, 67))
        );

        panelCommand.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Command", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("SansSerif", 1, 12))); // NOI18N

        org.jdesktop.layout.GroupLayout panelCommandLayout = new org.jdesktop.layout.GroupLayout(panelCommand);
        panelCommand.setLayout(panelCommandLayout);
        panelCommandLayout.setHorizontalGroup(
            panelCommandLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER)
            .add(panelCommandLayout.createSequentialGroup()
                .add(48, 48, 48)
                .add(panelCommandLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER)
                    .add(button_scala)
                    .add(button_delBaloon)
                    .add(button_validate))
                 .addContainerGap(38, Short.MAX_VALUE))
        );
        panelCommandLayout.setVerticalGroup(
            panelCommandLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER)
            .add(panelCommandLayout.createSequentialGroup()
                //.add(18, 18, 18)
                .add(button_validate)
                .add(17, 17, 17)
                .add(button_delBaloon)
                .add(18, 18, 18)
                .add(button_scala)
                .addContainerGap(0, Short.MAX_VALUE))
        );

        panelMyTurn.setBorder(javax.swing.BorderFactory.createTitledBorder("Is my turn?"));

        org.jdesktop.layout.GroupLayout panelMyTurnLayout = new org.jdesktop.layout.GroupLayout(panelMyTurn);
        panelMyTurn.setLayout(panelMyTurnLayout);
        panelMyTurnLayout.setHorizontalGroup(
            panelMyTurnLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER)
            .add(panelMyTurnLayout.createSequentialGroup()
                .add(54, 54, 54)
                .add(labelTurn)
                )//.addContainerGap(0,0))
        );
        panelMyTurnLayout.setVerticalGroup(
            panelMyTurnLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER)
            .add(panelMyTurnLayout.createSequentialGroup()
                //.add(0, 0, 0)
                .add(labelTurn)
                )//.addContainerGap(0, 0))
        );

        org.jdesktop.layout.GroupLayout jInternalFrame1Layout = new org.jdesktop.layout.GroupLayout(container_buttons.getContentPane());
        container_buttons.getContentPane().setLayout(jInternalFrame1Layout);
        jInternalFrame1Layout.setHorizontalGroup(
            jInternalFrame1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jInternalFrame1Layout.createSequentialGroup()
                //.add(20, 20, 20)
                .add(jInternalFrame1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, panelDeck, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, panelCommand, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, panelMyTurn, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jInternalFrame1Layout.setVerticalGroup(
            jInternalFrame1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jInternalFrame1Layout.createSequentialGroup()
                //.add(20, 20, 20)
                .add(panelDeck, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 142, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                //.add(18, 18, 18)
                .add(panelCommand, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                //.add(18, 18, 18)
                .add(panelMyTurn, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                //.add(298, 298, 298))
        );

        panelDeck.setBackground(Color.decode("#DCDCDC"));
        panelCommand.setBackground(Color.decode("#DCDCDC"));
        panelMyTurn.setBackground(Color.WHITE);

//        labelTurn.setText("YES");
//        labelTurn.setFont(new Font("Sans Serif", Font.ITALIC, 18));
//        labelTurn.setForeground(Color.GREEN);





//?????????????????????????????????????????????????????????????????????????????????????????????????????????
//       org.jdesktop.layout.GroupLayout panel1Layout = new org.jdesktop.layout.GroupLayout(panel1);
//        panel1.setLayout(panel1Layout);
//        panel1Layout.setHorizontalGroup(
//            panel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
//            .add(panel1Layout.createSequentialGroup()
//                .add(panel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
//                    .add(panel1Layout.createSequentialGroup()
//                        .add(42, 42, 42)
//                        .add(panel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
//                            .add(button_validate)
//                            .add(button_scala)
//                            .add(scopertaButton)))
//                    .add(panel1Layout.createSequentialGroup()
//                        .add(50, 50, 50)
//                        .add(panel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
//                            .add(button_passaTurno)
//                            .add(dorsoButton))))
//                .addContainerGap(34, Short.MAX_VALUE))
//            .add(panel1Layout.createSequentialGroup()
//                .add(20, 20, 20)
//                .add(button_delBaloon, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE)
//                .add(22, 22, 22))
//        );
//
//
//        panel1Layout.setVerticalGroup(
//            panel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
//            .add(panel1Layout.createSequentialGroup()
//                //.add(19, 19, 19)
//                .add(button_delBaloon, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 83, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
//                //.add(30, 30, 30)
//                .add(button_validate)
//                //.add(47, 47, 47)
//                .add(scopertaButton)
//                //.add(50, 50, 50)
//                .add(button_scala)
//                //.add(38, 38, 38)
//                .add(dorsoButton)
//                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 28, Short.MAX_VALUE)
//                .add(button_passaTurno)
//                .addContainerGap())
//        );



/*************************************************** test panel 1*******************************/





       button_delBaloon.addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                	playerActions.removeAllCardSetFromBaloon();
                    resetBaloon();

               }
        });


        button_passaTurno.addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                   String s=playerActions.playerCommit();
                   DialogBox d=new DialogBox();
                   d.message(s);
                }
        });



        button_validate.addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {



                   if(playerActions.addLineToBaloon()){
                       
                       cardsCombinations.increaseIndexLine();
//                       cardsCombinations.newLine();
                       //inserimento nuova riga da cancellare nel menù popup
                       JMenuItem cutMenuItem = new JMenuItem("Cancels "+numberOfRows+"° row");
                       System.out.println("numberOfRows iniziale: "+numberOfRows);
                       numberOfRows++;
                       currentLine++;
                       cutMenuItem.addActionListener(actionListener);
                       popupMenu.add(cutMenuItem);

                   }else{
                        DialogBox dialog = new DialogBox();
//                        JFrame f = new JFrame();
                        dialog.message("Ultimo set di carte inserite non valido!");
                   }
                //  else{//inserire popup di dialogo che non è validato}
                }
        });



        

  /**********************************************************************/
        //inizializzo JItemMenù
        ArrayList<JMenuItem> arrayItem=new ArrayList<JMenuItem>();
        for(int i=0;i<15;i++){
            arrayItem.add(new JMenuItem("Scarta Card"));
        }


        ArrayList<JMenuItem> arrayItemAttach=new ArrayList<JMenuItem>();
        for(int i=0;i<15;i++){
            arrayItemAttach.add(new JMenuItem("Attacca"));
        }


        ArrayList<JPopupMenu> arrayPopup=new ArrayList<JPopupMenu>();
        for(int i=0;i<15;i++){
            arrayPopup.add(new JPopupMenu());
        }



        
        final ActionListener actionListener0 = new ActionListener() {
            public void actionPerformed(ActionEvent actionEvent) {
                System.out.println("STAMPA ACTION COMMAND: "+actionEvent.getActionCommand());
                if(actionEvent.getActionCommand().equals("Scarta Card")){
                    System.out.println("carta scartata in posizione: 0");
                    discard(0);
                }
                if(actionEvent.getActionCommand().equals("Attacca")){
                    System.out.println("Zona Attacca");
                    c.setCardPosition(0,playerActions);
                    positionCartForAttach=0;

                }
            }
        };

        final ActionListener actionListener1 = new ActionListener() {
            public void actionPerformed(ActionEvent actionEvent) {
                if(actionEvent.getActionCommand().equals("Scarta Card")){
                    System.out.println("carta scartata in posizione: 1");
                    discard(1);
                }
                if(actionEvent.getActionCommand().equals("Attacca")){
                    System.out.println("Zona Attacca");
                    c.setCardPosition(1,playerActions);
                    positionCartForAttach=1;
                }
            }
        };

        final ActionListener actionListener2 = new ActionListener() {
            public void actionPerformed(ActionEvent actionEvent) {
                if(actionEvent.getActionCommand().equals("Scarta Card")){
                    System.out.println("carta scartata in posizione: 2");
                    discard(2);
                }
                if(actionEvent.getActionCommand().equals("Attacca")){
                    System.out.println("Zona Attacca");
                    c.setCardPosition(2,playerActions);
                    positionCartForAttach=2;
                }
            }
        };

        final ActionListener actionListener3 = new ActionListener() {
            public void actionPerformed(ActionEvent actionEvent) {
                if(actionEvent.getActionCommand().equals("Scarta Card")){
                    System.out.println("carta scartata in posizione: 3");
                    discard(3);
                }
                if(actionEvent.getActionCommand().equals("Attacca")){
                    System.out.println("Zona Attacca");
                    c.setCardPosition(3,playerActions);
                    positionCartForAttach=3;
                }
            }
        };

        final ActionListener actionListener4 = new ActionListener() {
            public void actionPerformed(ActionEvent actionEvent) {
                if(actionEvent.getActionCommand().equals("Scarta Card")){
                    System.out.println("carta scartata in posizione: 4");
                    discard(4);
                }
                if(actionEvent.getActionCommand().equals("Attacca")){
                    System.out.println("Zona Attacca");
                    c.setCardPosition(4,playerActions);
                    positionCartForAttach=4;
                }
            }
        };

        final ActionListener actionListener5 = new ActionListener() {
            public void actionPerformed(ActionEvent actionEvent) {
                if(actionEvent.getActionCommand().equals("Scarta Card")){
                    System.out.println("carta scartata in posizione: 5");
                    discard(5);
                }
                if(actionEvent.getActionCommand().equals("Attacca")){
                    System.out.println("Zona Attacca");
                    c.setCardPosition(5,playerActions);
                    positionCartForAttach=5;
                }
            }
        };

        final ActionListener actionListener6 = new ActionListener() {
            public void actionPerformed(ActionEvent actionEvent) {
                if(actionEvent.getActionCommand().equals("Scarta Card")){
                    System.out.println("carta scartata in posizione: 6");
                    discard(6);
                }
                if(actionEvent.getActionCommand().equals("Attacca")){
                    System.out.println("Zona Attacca");
                    c.setCardPosition(6,playerActions);
                    positionCartForAttach=6;
                }
            }
        };

        final ActionListener actionListener7 = new ActionListener() {
            public void actionPerformed(ActionEvent actionEvent) {
                if(actionEvent.getActionCommand().equals("Scarta Card")){
                    System.out.println("carta scartata in posizione: 7");
                    discard(7);
                }
                if(actionEvent.getActionCommand().equals("Attacca")){
                    System.out.println("Zona Attacca");
                    c.setCardPosition(7,playerActions);
                    positionCartForAttach=7;
                }
            }
        };

        final ActionListener actionListener8 = new ActionListener() {
            public void actionPerformed(ActionEvent actionEvent) {
                if(actionEvent.getActionCommand().equals("Scarta Card")){
                    System.out.println("carta scartata in posizione: 8");
                    discard(8);
                }
                if(actionEvent.getActionCommand().equals("Attacca")){
                    System.out.println("Zona Attacca");
                    c.setCardPosition(8,playerActions);
                    positionCartForAttach=8;
                }
            }
        };

        final ActionListener actionListener9 = new ActionListener() {
            public void actionPerformed(ActionEvent actionEvent) {
                if(actionEvent.getActionCommand().equals("Scarta Card")){
                    System.out.println("carta scartata in posizione: 9");
                    discard(9);
                }
                if(actionEvent.getActionCommand().equals("Attacca")){
                    System.out.println("Zona Attacca");
                    c.setCardPosition(9,playerActions);
                    positionCartForAttach=9;
                }
            }
        };

        final ActionListener actionListener10 = new ActionListener() {
            public void actionPerformed(ActionEvent actionEvent) {
                if(actionEvent.getActionCommand().equals("Scarta Card")){
                    System.out.println("carta scartata in posizione: 10");
                    discard(10);
                }
                if(actionEvent.getActionCommand().equals("Attacca")){
                    System.out.println("Zona Attacca");
                    c.setCardPosition(10,playerActions);
                    positionCartForAttach=10;
                }
            }
        };

        final ActionListener actionListener11 = new ActionListener() {
            public void actionPerformed(ActionEvent actionEvent) {
                if(actionEvent.getActionCommand().equals("Scarta Card")){
                    System.out.println("carta scartata in posizione: 11");
                    discard(11);
                }
                if(actionEvent.getActionCommand().equals("Attacca")){
                    System.out.println("Zona Attacca");
                    c.setCardPosition(11,playerActions);
                    positionCartForAttach=11;
                }
            }
        };

        final ActionListener actionListener12 = new ActionListener() {
            public void actionPerformed(ActionEvent actionEvent) {
                if(actionEvent.getActionCommand().equals("Scarta Card")){
                    System.out.println("carta scartata in posizione: 12");
                    discard(12);
                }
                if(actionEvent.getActionCommand().equals("Attacca")){
                    System.out.println("Zona Attacca");
                    c.setCardPosition(12,playerActions);
                    positionCartForAttach=12;
                }
            }
        };

        final ActionListener actionListener13 = new ActionListener() {
            public void actionPerformed(ActionEvent actionEvent) {
                if(actionEvent.getActionCommand().equals("Scarta Card")){
                    System.out.println("carta scartata in posizione: 13");
                    discard(13);
                }
                if(actionEvent.getActionCommand().equals("Attacca")){
                    System.out.println("Zona Attacca");
                    c.setCardPosition(13,playerActions);
                    positionCartForAttach=13;
                }
            }
        };


        
        

        MouseListener mouseListener0 = new PopupMenuShower(arrayPopup.get(0));
        arrayButton.get(0).addMouseListener(mouseListener0);
        arrayItem.get(0).addActionListener(actionListener0);
        arrayItemAttach.get(0).addActionListener(actionListener0);
        arrayPopup.get(0).add(arrayItem.get(0));
        arrayPopup.get(0).add(arrayItemAttach.get(0));

        MouseListener mouseListener1 = new PopupMenuShower(arrayPopup.get(1));
        arrayButton.get(1).addMouseListener(mouseListener1);
        arrayItem.get(1).addActionListener(actionListener1);
        arrayItemAttach.get(1).addActionListener(actionListener1);
        arrayPopup.get(1).add(arrayItem.get(1));
        arrayPopup.get(1).add(arrayItemAttach.get(1));

        MouseListener mouseListener2 = new PopupMenuShower(arrayPopup.get(2));
        arrayButton.get(2).addMouseListener(mouseListener2);
        arrayItem.get(2).addActionListener(actionListener2);
        arrayItemAttach.get(2).addActionListener(actionListener2);
        arrayPopup.get(2).add(arrayItem.get(2));
        arrayPopup.get(2).add(arrayItemAttach.get(2));

        MouseListener mouseListener3 = new PopupMenuShower(arrayPopup.get(3));
        arrayButton.get(3).addMouseListener(mouseListener3);
        arrayItem.get(3).addActionListener(actionListener3);
        arrayItemAttach.get(3).addActionListener(actionListener3);
        arrayPopup.get(3).add(arrayItem.get(3));
        arrayPopup.get(3).add(arrayItemAttach.get(3));

        MouseListener mouseListener4 = new PopupMenuShower(arrayPopup.get(4));
        arrayButton.get(4).addMouseListener(mouseListener4);
        arrayItem.get(4).addActionListener(actionListener4);
        arrayItemAttach.get(4).addActionListener(actionListener4);
        arrayPopup.get(4).add(arrayItem.get(4));
        arrayPopup.get(4).add(arrayItemAttach.get(4));

        MouseListener mouseListener5 = new PopupMenuShower(arrayPopup.get(5));
        arrayButton.get(5).addMouseListener(mouseListener5);
        arrayItem.get(5).addActionListener(actionListener5);
        arrayItemAttach.get(5).addActionListener(actionListener5);
        arrayPopup.get(5).add(arrayItem.get(5));
        arrayPopup.get(5).add(arrayItemAttach.get(5));

        MouseListener mouseListener6 = new PopupMenuShower(arrayPopup.get(6));
        arrayButton.get(6).addMouseListener(mouseListener6);
        arrayItem.get(6).addActionListener(actionListener6);
        arrayItemAttach.get(6).addActionListener(actionListener6);
        arrayPopup.get(6).add(arrayItem.get(6));
        arrayPopup.get(6).add(arrayItemAttach.get(6));

        MouseListener mouseListener7 = new PopupMenuShower(arrayPopup.get(7));
        arrayButton.get(7).addMouseListener(mouseListener7);
        arrayItem.get(7).addActionListener(actionListener7);
        arrayItemAttach.get(7).addActionListener(actionListener7);
        arrayPopup.get(7).add(arrayItem.get(7));
        arrayPopup.get(7).add(arrayItemAttach.get(7));

        MouseListener mouseListener8 = new PopupMenuShower(arrayPopup.get(8));
        arrayButton.get(8).addMouseListener(mouseListener8);
        arrayItem.get(8).addActionListener(actionListener8);
        arrayItemAttach.get(8).addActionListener(actionListener8);
        arrayPopup.get(8).add(arrayItem.get(8));
        arrayPopup.get(8).add(arrayItemAttach.get(8));

        MouseListener mouseListener9 = new PopupMenuShower(arrayPopup.get(9));
        arrayButton.get(9).addMouseListener(mouseListener9);
        arrayItem.get(9).addActionListener(actionListener9);
        arrayItemAttach.get(9).addActionListener(actionListener9);
        arrayPopup.get(9).add(arrayItem.get(9));
        arrayPopup.get(9).add(arrayItemAttach.get(9));

        MouseListener mouseListener10 = new PopupMenuShower(arrayPopup.get(10));
        arrayButton.get(10).addMouseListener(mouseListener10);
        arrayItem.get(10).addActionListener(actionListener10);
        arrayItemAttach.get(10).addActionListener(actionListener10);
        arrayPopup.get(10).add(arrayItem.get(10));
        arrayPopup.get(10).add(arrayItemAttach.get(10));

        MouseListener mouseListener11 = new PopupMenuShower(arrayPopup.get(11));
        arrayButton.get(11).addMouseListener(mouseListener11);
        arrayItem.get(11).addActionListener(actionListener11);
        arrayItemAttach.get(11).addActionListener(actionListener11);
        arrayPopup.get(11).add(arrayItem.get(11));
        arrayPopup.get(11).add(arrayItemAttach.get(11));

        MouseListener mouseListener12 = new PopupMenuShower(arrayPopup.get(12));
        arrayButton.get(12).addMouseListener(mouseListener12);
        arrayItem.get(12).addActionListener(actionListener12);
        arrayItemAttach.get(12).addActionListener(actionListener12);
        arrayPopup.get(12).add(arrayItem.get(12));
        arrayPopup.get(12).add(arrayItemAttach.get(12));

        MouseListener mouseListener13 = new PopupMenuShower(arrayPopup.get(13));
        arrayButton.get(13).addMouseListener(mouseListener13);
        arrayItem.get(13).addActionListener(actionListener13);
        arrayItemAttach.get(13).addActionListener(actionListener13);
        arrayPopup.get(13).add(arrayItem.get(13));
        arrayPopup.get(13).add(arrayItemAttach.get(13));





        //scarta menù popup tasto destro
        arrayButton.get(0).addMouseListener(
            new MouseAdapter(){
                @Override
             public void mousePressed(MouseEvent e){
               if (e.getButton() == MouseEvent.BUTTON3) {
               System.out.println("TASTO DESTRO CLICCATO.");
               System.out.println(e.isPopupTrigger());
             }
        }});

        arrayButton.get(1).addMouseListener(
            new MouseAdapter(){
                @Override
             public void mousePressed(MouseEvent e) {
               if (e.getButton() == MouseEvent.BUTTON3) {
               System.out.println("TASTO DESTRO CLICCATO.");
               System.out.println(e.isPopupTrigger());
             }
        }});

        arrayButton.get(2).addMouseListener(
            new MouseAdapter(){
                @Override
             public void mousePressed(MouseEvent e) {
               if (e.getButton() == MouseEvent.BUTTON3) {
               System.out.println("TASTO DESTRO CLICCATO.");
               System.out.println(e.isPopupTrigger());
             }
        }});

        arrayButton.get(3).addMouseListener(
            new MouseAdapter(){
                @Override
             public void mousePressed(MouseEvent e) {
               if (e.getButton() == MouseEvent.BUTTON3) {
               System.out.println("TASTO DESTRO CLICCATO.");
               System.out.println(e.isPopupTrigger());
             }
        }});

        arrayButton.get(4).addMouseListener(
            new MouseAdapter(){
                @Override
             public void mousePressed(MouseEvent e) {
               if (e.getButton() == MouseEvent.BUTTON3) {
               System.out.println("TASTO DESTRO CLICCATO.");
               System.out.println(e.isPopupTrigger());
             }
        }});

        arrayButton.get(5).addMouseListener(
            new MouseAdapter(){
                @Override
             public void mousePressed(MouseEvent e) {
               if (e.getButton() == MouseEvent.BUTTON3) {
               System.out.println("TASTO DESTRO CLICCATO.");
               System.out.println(e.isPopupTrigger());
             }
        }});

        arrayButton.get(6).addMouseListener(
            new MouseAdapter(){
                @Override
             public void mousePressed(MouseEvent e) {
               if (e.getButton() == MouseEvent.BUTTON3) {
               System.out.println("TASTO DESTRO CLICCATO.");
               System.out.println(e.isPopupTrigger());
             }
        }});

        arrayButton.get(7).addMouseListener(
            new MouseAdapter(){
                @Override
             public void mousePressed(MouseEvent e) {
               if (e.getButton() == MouseEvent.BUTTON3) {
               System.out.println("TASTO DESTRO CLICCATO.");
               System.out.println(e.isPopupTrigger());
             }
        }});

        arrayButton.get(8).addMouseListener(
            new MouseAdapter(){
                @Override
             public void mousePressed(MouseEvent e) {
               if (e.getButton() == MouseEvent.BUTTON3) {
               System.out.println("TASTO DESTRO CLICCATO.");
               System.out.println(e.isPopupTrigger());
             }
        }});

        arrayButton.get(9).addMouseListener(
            new MouseAdapter(){
                @Override
             public void mousePressed(MouseEvent e) {
               if (e.getButton() == MouseEvent.BUTTON3) {
               System.out.println("TASTO DESTRO CLICCATO.");
               System.out.println(e.isPopupTrigger());
             }
        }});

        arrayButton.get(10).addMouseListener(
            new MouseAdapter(){
                @Override
             public void mousePressed(MouseEvent e) {
               if (e.getButton() == MouseEvent.BUTTON3) {
               System.out.println("TASTO DESTRO CLICCATO.");
               System.out.println(e.isPopupTrigger());
             }
        }});

        arrayButton.get(11).addMouseListener(
            new MouseAdapter(){
                @Override
             public void mousePressed(MouseEvent e) {
               if (e.getButton() == MouseEvent.BUTTON3) {
               System.out.println("TASTO DESTRO CLICCATO.");
               System.out.println(e.isPopupTrigger());
             }
        }});

        arrayButton.get(12).addMouseListener(
            new MouseAdapter(){
                @Override
             public void mousePressed(MouseEvent e) {
               if (e.getButton() == MouseEvent.BUTTON3) {
               System.out.println("TASTO DESTRO CLICCATO.");
               System.out.println(e.isPopupTrigger());
             }
        }});

        arrayButton.get(13).addMouseListener(
            new MouseAdapter(){
                @Override
             public void mousePressed(MouseEvent e) {
               if (e.getButton() == MouseEvent.BUTTON3) {
               System.out.println("TASTO DESTRO CLICCATO.");
               System.out.println(e.isPopupTrigger());
             }
        }});




/**********************************************************************/
        //esempio di listener sui bottoni/carta

        arrayButton.get(0).addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    Boolean result=cardsCombinations.insertIntoThink(cards_on_hands.getCard(0));
                    System.out.println("RISULTATO BOOLEAN: "+result);

                       boolean b=playerActions.addCardToBaloon(0);
                       
                    
                    //togliamo la carta dalla mano               
             /*       if(result==true){
                        arrayButton.get(0).setVisible(false);
                        visible.set(0, false);
                    }else{
                        arrayButton.get(0).setVisible(true);
                    }*/
                }
            }
        );

        arrayButton.get(1).addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    Boolean result=cardsCombinations.insertIntoThink(cards_on_hands.getCard(1));
                    
                        playerActions.addCardToBaloon(1);
                    
                    
            /*        if(result==true){
                        arrayButton.get(1).setVisible(false);
                        visible.set(1, false);
                    }else{
                        arrayButton.get(1).setVisible(true);
                    }*/
                }
            }
        );
        arrayButton.get(2).addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    Boolean result=cardsCombinations.insertIntoThink(cards_on_hands.getCard(2));
                    playerActions.addCardToBaloon(2);
                    
                 /*   if(result==true){
                        arrayButton.get(2).setVisible(false);
                        visible.set(2, false);
                    }else{
                        arrayButton.get(2).setVisible(true);
                    }*/
                }
            }
        );
        arrayButton.get(3).addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    Boolean result=cardsCombinations.insertIntoThink(cards_on_hands.getCard(3));
                    playerActions.addCardToBaloon(3);
                    
                  /*  if(result==true){
                        arrayButton.get(3).setVisible(false);
                        visible.set(3, false);
                    }else{
                        arrayButton.get(3).setVisible(true);
                    }*/
                }
            }
        );
        arrayButton.get(4).addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    Boolean result=cardsCombinations.insertIntoThink(cards_on_hands.getCard(4));
                    playerActions.addCardToBaloon(4);
                    
                  /*  if(result==true){
                        arrayButton.get(4).setVisible(false);
                        visible.set(4, false);
                    }else{
                        arrayButton.get(4).setVisible(true);
                    }*/
                }
            }
        );
        arrayButton.get(5).addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    Boolean result=cardsCombinations.insertIntoThink(cards_on_hands.getCard(5));
                    playerActions.addCardToBaloon(5);
                    
                    /* if(result==true){
                        arrayButton.get(5).setVisible(false);
                        visible.set(5, false);
                    }else{
                        arrayButton.get(5).setVisible(true);
                    }*/
                }
            }
        );
        arrayButton.get(6).addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    Boolean result=cardsCombinations.insertIntoThink(cards_on_hands.getCard(6));
                    playerActions.addCardToBaloon(6);
                    
                    /*if(result==true){
                        arrayButton.get(6).setVisible(false);
                        visible.set(6, false);
                    }else{
                        arrayButton.get(6).setVisible(true);
                    }*/
                }
            }
        );
        arrayButton.get(7).addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    Boolean result=cardsCombinations.insertIntoThink(cards_on_hands.getCard(7));
                    playerActions.addCardToBaloon(7);
                    
                  /*  if(result==true){
                        arrayButton.get(7).setVisible(false);
                        visible.set(7, false);
                    }else{
                        arrayButton.get(7).setVisible(true);
                    }*/
                }
            }
        );
        arrayButton.get(8).addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    Boolean result=cardsCombinations.insertIntoThink(cards_on_hands.getCard(8));
                    playerActions.addCardToBaloon(8);
                    
                   /* if(result==true){
                        arrayButton.get(8).setVisible(false);
                        visible.set(8, false);
                    }else{
                        arrayButton.get(8).setVisible(true);
                    }*/
                }
            }
        );
        arrayButton.get(9).addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    Boolean result=cardsCombinations.insertIntoThink(cards_on_hands.getCard(9));
                    playerActions.addCardToBaloon(9);
                   
                   /* if(result==true){
                        arrayButton.get(9).setVisible(false);
                        visible.set(9, false);
                    }else{
                        arrayButton.get(9).setVisible(true);
                    }*/
                }
            }
        );
        arrayButton.get(10).addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    Boolean result=cardsCombinations.insertIntoThink(cards_on_hands.getCard(10));
                    playerActions.addCardToBaloon(10);
                    
                    /*if(result==true){
                        arrayButton.get(10).setVisible(false);
                        visible.set(10, false);
                    }else{
                        arrayButton.get(10).setVisible(true);
                    }*/
                }
            }
        );
        arrayButton.get(11).addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    Boolean result=cardsCombinations.insertIntoThink(cards_on_hands.getCard(11));
                    playerActions.addCardToBaloon(11);
                   
                    /*if(result==true){
                        arrayButton.get(11).setVisible(false);
                        visible.set(11, false);
                    }else{
                        arrayButton.get(11).setVisible(true);
                    }*/
                }
            }
        );
        arrayButton.get(12).addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    Boolean result=cardsCombinations.insertIntoThink(cards_on_hands.getCard(12));
                    playerActions.addCardToBaloon(12);
                   
                   /* if(result==true){
                        arrayButton.get(12).setVisible(false);
                        visible.set(12, false);
                    }else{
                        arrayButton.get(12).setVisible(true);
                    }*/
                }
            }
        );
        arrayButton.get(13).addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    Boolean result=cardsCombinations.insertIntoThink(cards_on_hands.getCard(13));
                    playerActions.addCardToBaloon(13);
                   
                    /*if(result==true){
                        arrayButton.get(13).setVisible(false);
                        visible.set(13, false);
                    }else{
                        arrayButton.get(13).setVisible(true);
                    }*/
                }
            }
        );

        


      

        //carteInMano.add(new JButton("OK"));

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
    /*    layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()

            .add(32, 32, 32)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(cardOnTable,0, 1918, Short.MAX_VALUE)
                    .add(carteInMano)
                    .addContainerGap(1200, Short.MAX_VALUE))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap(383, Short.MAX_VALUE)
                .add(button_scala)
                .add(372, 372, 372))
                //.add(0, 618, Short.MAX_VALUE)


               // .add(carteInMano, 100,400,400)
                .add(button_scala)

                )
        );*/

       container_buttons.setLayout(experimentLayout);
       experimentLayout.setAlignment(FlowLayout.CENTER);
       


       dorsoButton.addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    if(isMyTurn()){
                        playerActions.drawFromHeel();
                    }else{
                        DialogBox d=new DialogBox();
                        d.message("Non è possibile. Aspettare il proprio turno");
                    }
                    
                }
            }
        );

        scopertaButton.addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    if(isMyTurn()){
                        Card last=new Card();

                        playerActions.drawFromWell();
                        last=playerActions.getLastCardFromWell();
                        scopertaButton.setIcon(last.getIcon());
                    }else{
                        DialogBox d=new DialogBox();
                        d.message("Non è possibile. Aspettare il proprio turno");
                    }

                    
                }
            }
        );

       

       cardsOnHand.setVisible(true);
       container_buttons.setVisible(true);

       //color snow:#FFFAFA
       cardsOnHand.setBackground(Color.decode("#D3D3D3"));
       container_buttons.setBackground(Color.decode("#DCDCDC"));
       think.setBackground(Color.decode("#DCDCDC"));
       panel1.setBackground(Color.decode("#DCDCDC"));
      

       container_buttons.getContentPane().add(panel1, BorderLayout.NORTH);
      

       //jButton2.setText("Bottone");


       

        dealCards();

        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createSequentialGroup()
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER)
                        .add(layout.createSequentialGroup()
                            //primo parametro varia la lunghezza di carte in tavola
                            .add(cardOnTable,850, 850, 850)
                            .add(think,190,190,190)
                        //.add(container_buttons, 100, 100, Short.MAX_VALUE)
                        //primo parametro cambia la dimensione x del container button
                        .add(container_buttons, 215, 215, 215)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 0, 0)
                    )
                        //.add(215, 215, 215))
                    .add(layout.createSequentialGroup()
                        //primo parametro aumenta la lunghezza della tabella carte in mano
                        //.add(carteInMano,1200, 1200, Short.MAX_VALUE)
                        
                       // 
                        //primo parametro fa rientrare il bottone
                        //.add(container_buttons, 50, 50, Short.MAX_VALUE)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                       /*     .add(button_validate)
                            .add(button_attacca)
                            .add(button_scala)*/
                        .add(cardsOnHand, 1140, 1140, 1140)
                        .add(think,0,0,0)
                        
                        
                    )
                    .add(layout.createSequentialGroup()
                       //.add(container_buttons, 200, 300, Short.MAX_VALUE)
                    )
                    .addContainerGap(0, 0)).add(labelStat)))



                  /*      .add(button_attacca)
                        
                        .add(button_scala)
                        .addContainerGap(1000, Short.MAX_VALUE))))*/
                    
                        
        );


       


        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                //.add(10, 10, 10)
                .add(cardOnTable,570, 570, 570)

                //.add(1, 1, 1)
                //.add(carteInMano,170, 400, Short.MAX_VALUE)
                .add(cardsOnHand, 150, 150, 150)
                //.add(container_buttons, 100, 100, Short.MAX_VALUE)
                //
                .addContainerGap(0, Short.MAX_VALUE))
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()

            //primo parametro aumenta la lunghezza del baloon
               /* .add(button_validate)
                .add(button_attacca)
                .add(0,40,40)
                .add(button_scala)*/
            //.add(container_buttons, 50, 50, Short.MAX_VALUE)
                .add(think,570,570,570)
                
                //.add(0, 20, 20)
                //.add(44, 44, 44)
                //.add(container_buttons, 100, 100, Short.MAX_VALUE)
                

                .addContainerGap(0, Short.MAX_VALUE)
                .add(labelStat)
                )
                .add(container_buttons, 570, 570, 570)
        );



       pack();
    }

    
//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                new DraftLayout().setVisible(true);
//            }
//        });
//    }

    //inizializza le aree delle carte nel tavolo
    private void InitialPositionVector() {

        PositionArea area1=new PositionArea();
        area1.CreateAreaInRiga(10,20);

        PositionArea area2=new PositionArea();
        area1.CreateAreaInRiga(175,20);

        PositionArea area3=new PositionArea();
        area1.CreateAreaInRiga(340,20);

        PositionArea area4=new PositionArea();
        area1.CreateAreaInRiga(505,20);

        PositionArea area5=new PositionArea();
        area1.CreateAreaInRiga(670,20);

        //cambio riga
        PositionArea area6=new PositionArea();
        area1.CreateAreaInRiga(10,145);

        PositionArea area7=new PositionArea();
        area1.CreateAreaInRiga(175,145);

        PositionArea area8=new PositionArea();
        area1.CreateAreaInRiga(340,145);

        PositionArea area9=new PositionArea();
        area1.CreateAreaInRiga(505,145);

        PositionArea area10=new PositionArea();
        area1.CreateAreaInRiga(670,145);

        //cambio riga
        PositionArea area11=new PositionArea();
        area1.CreateAreaInRiga(10,275);

        PositionArea area12=new PositionArea();
        area1.CreateAreaInRiga(175,275);

        PositionArea area13=new PositionArea();
        area1.CreateAreaInRiga(340,275);

        PositionArea area14=new PositionArea();
        area1.CreateAreaInRiga(505,275);

        PositionArea area15=new PositionArea();
        area1.CreateAreaInRiga(670,275);

        //cambio riga
        PositionArea area16=new PositionArea();
        area1.CreateAreaInRiga(10,405);

        PositionArea area17=new PositionArea();
        area1.CreateAreaInRiga(175,405);

        PositionArea area18=new PositionArea();
        area1.CreateAreaInRiga(340,405);

        PositionArea area19=new PositionArea();
        area1.CreateAreaInRiga(505,405);

        PositionArea area20=new PositionArea();
        area1.CreateAreaInRiga(670,405);

    
/*
        PositionArea area3=new PositionArea(
                                    new Punti(390,10),
                                    new Punti(405,10),
                                    new Punti(420,10),
                                    new Punti(435,10),
                                    new Punti(450,10),
                                    new Punti(475,10),
                                    new Punti(490,10));
*/
        vettore.add(area1);
        vettore.add(area2);
        vettore.add(area3);
        vettore.add(area4);
        vettore.add(area5);
        vettore.add(area6);
        vettore.add(area7);
        vettore.add(area8);
        vettore.add(area9);
        vettore.add(area10);
        vettore.add(area11);
        vettore.add(area12);
        vettore.add(area13);
        vettore.add(area14);
        vettore.add(area15);
        vettore.add(area16);
        vettore.add(area17);
        vettore.add(area18);
        vettore.add(area19);
        vettore.add(area20);
       // vettore.add(area2);
       // vettore.add(area3);
     
    }


    //disegna le carte in mano
    private void dealCards(){
        
        org.jdesktop.layout.GroupLayout jInternalFrame1Layout = new org.jdesktop.layout.GroupLayout(cardsOnHand.getContentPane());
        cardsOnHand.getContentPane().setLayout(jInternalFrame1Layout);
        jInternalFrame1Layout.setHorizontalGroup(
            jInternalFrame1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jInternalFrame1Layout.createSequentialGroup()
                .add(arrayButton.get(0))
                .addContainerGap(423, Short.MAX_VALUE))
            .add(jInternalFrame1Layout.createSequentialGroup()
                .add(80,80,80)
                .add(arrayButton.get(1))
                .addContainerGap(423, Short.MAX_VALUE))
            .add(jInternalFrame1Layout.createSequentialGroup()
                .add(160,160,160)
                .add(arrayButton.get(2))
                .addContainerGap(423, Short.MAX_VALUE))
            .add(jInternalFrame1Layout.createSequentialGroup()
                .add(240,240,240)
                .add(arrayButton.get(3))
                .addContainerGap(423, Short.MAX_VALUE))
            .add(jInternalFrame1Layout.createSequentialGroup()
                .add(320,320,320)
                .add(arrayButton.get(4))
                .addContainerGap(423, Short.MAX_VALUE))
            .add(jInternalFrame1Layout.createSequentialGroup()
                .add(400,400,400)
                .add(arrayButton.get(5))
                .addContainerGap(423, Short.MAX_VALUE))
            .add(jInternalFrame1Layout.createSequentialGroup()
                .add(480,480,480)
                .add(arrayButton.get(6))
                .addContainerGap(423, Short.MAX_VALUE))
            .add(jInternalFrame1Layout.createSequentialGroup()
                .add(560,560,560)
                .add(arrayButton.get(7))
                .addContainerGap(423, Short.MAX_VALUE))
            .add(jInternalFrame1Layout.createSequentialGroup()
                .add(640,640,640)
                .add(arrayButton.get(8))
                .addContainerGap(423, Short.MAX_VALUE))
            .add(jInternalFrame1Layout.createSequentialGroup()
                .add(720,720,720)
                .add(arrayButton.get(9))
                .addContainerGap(423, Short.MAX_VALUE))
            .add(jInternalFrame1Layout.createSequentialGroup()
                .add(800,800,800)
                .add(arrayButton.get(10))
                .addContainerGap(423, Short.MAX_VALUE))
            .add(jInternalFrame1Layout.createSequentialGroup()
                .add(880,880,880)
                .add(arrayButton.get(11))
                .addContainerGap(423, Short.MAX_VALUE))
            .add(jInternalFrame1Layout.createSequentialGroup()
                .add(960,960,960)
                .add(arrayButton.get(12))
                .addContainerGap(423, Short.MAX_VALUE))
            .add(jInternalFrame1Layout.createSequentialGroup()
                .add(1040,1040,1040)
                .add(arrayButton.get(13))
                .addContainerGap(423, Short.MAX_VALUE))
                


        );
        jInternalFrame1Layout.setVerticalGroup(
            jInternalFrame1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jInternalFrame1Layout.createSequentialGroup()
                .add(arrayButton.get(0))
                .addContainerGap(46, Short.MAX_VALUE))
            .add(jInternalFrame1Layout.createSequentialGroup()
                .add(arrayButton.get(1))
                .addContainerGap(46, Short.MAX_VALUE))
            .add(jInternalFrame1Layout.createSequentialGroup()
                .add(arrayButton.get(2))
                .addContainerGap(46, Short.MAX_VALUE))
            .add(jInternalFrame1Layout.createSequentialGroup()
                .add(arrayButton.get(3))
                .addContainerGap(46, Short.MAX_VALUE))
            .add(jInternalFrame1Layout.createSequentialGroup()
                .add(arrayButton.get(4))
                .addContainerGap(46, Short.MAX_VALUE))
            .add(jInternalFrame1Layout.createSequentialGroup()
                .add(arrayButton.get(5))
                .addContainerGap(46, Short.MAX_VALUE))
            .add(jInternalFrame1Layout.createSequentialGroup()
                .add(arrayButton.get(6))
                .addContainerGap(46, Short.MAX_VALUE))
            .add(jInternalFrame1Layout.createSequentialGroup()
                .add(arrayButton.get(7))
                .addContainerGap(46, Short.MAX_VALUE))
            .add(jInternalFrame1Layout.createSequentialGroup()
                .add(arrayButton.get(8))
                .addContainerGap(46, Short.MAX_VALUE))
            .add(jInternalFrame1Layout.createSequentialGroup()
                .add(arrayButton.get(9))
                .addContainerGap(46, Short.MAX_VALUE))
            .add(jInternalFrame1Layout.createSequentialGroup()
                .add(arrayButton.get(10))
                .addContainerGap(46, Short.MAX_VALUE))
            .add(jInternalFrame1Layout.createSequentialGroup()
                .add(arrayButton.get(11))
                .addContainerGap(46, Short.MAX_VALUE))
            .add(jInternalFrame1Layout.createSequentialGroup()
                .add(arrayButton.get(12))
                .addContainerGap(46, Short.MAX_VALUE))
            .add(jInternalFrame1Layout.createSequentialGroup()
                .add(arrayButton.get(13))
                .addContainerGap(46, Short.MAX_VALUE))
        );
    }


    private int foundIndex(String simbol){
        int i;
        for(i=0;i<cards_on_hands.size();i++){
            if(cards_on_hands.getCard(i).getSymbol().equals(simbol)){
                break;
            }
        }
        return i;
    }


    public void goGraphic(){

        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
               //new DraftLayout().setVisible(true);
            }
        });
    }

     public void setCards(CardSet c){
    	 System.out.println("[DraftLayout || setCard()] Inserimento carte");
            int i=0;

            while(i<cards_on_hands.size()){
                cards_on_hands.removeCard(i);
            }

            for(int j=0;j<c.size();j++){

                cards_on_hands.addCard(c.getCard(j));

            }

/*
            for(int i=0;i<c.size();i++){
            	System.out.println("                     Carta: "+c.getCard(i).getSymbol()+" "+c.getCard(i).getSuit()+ " path icona:"+c.getCard(i).getIcon());
                cards_on_hands.setCard(i, c.getCard(i));
                
            }*/
            for(int j=0;j<cards_on_hands.size();j++){
                arrayButton.get(j).setIcon(cards_on_hands.getCard(j).getIcon());
            }

    }

    public void setVisibleCards(){
        
        for(int i=0;i<arrayButton.size();i++){
           try{
              if(cards_on_hands.getCard(i).getSuit()!=null){
                 arrayButton.get(i).setVisible(true);
              }else{
                  arrayButton.get(i).setVisible(false);
              }
           }catch(Exception e){
             arrayButton.get(i).setVisible(false);
           }
        }


    }


    public void setPlayerActions(PlayerActions p){
        this.playerActions=p;
    }

  
    private void discard(int position){
        playerActions.discardToWell(position);
        //playerActions.setCardsOnHands();
        discardCard=playerActions.getLastCardFromWell();
        scopertaButton.setIcon(discardCard.getIcon());
    }

    public void updateDiscard(Card c){
        scopertaButton.setIcon(c.getIcon());
        System.out.println("entrato nell'UPDATE!!!");
    }


    public void tryToAddOrReplace(int positionCardSet){
        if(positionCartForAttach!=-1){
            playerActions.tryToAddOrRepleaceCard(positionCartForAttach, positionCardSet);
        }
    }

    public void draw(){

       //svuoto il vettore delle immagini
        int j=0;
        while(j<vettoreImage.size()){
            vettoreImage.remove(j);
        }

        CardSetList cardsOnTable= new CardSetList();
        System.out.println("[DraftLayout || Scala listener] sto per ottenere le carte che sono sul tavolo");
        cardsOnTable = playerActions.getCardsOnTheTable();

        int numberOfCard=0;

        int k;
        for(int z=0;z<cardsOnTable.size();z++){
            k=0;
            while(k<7){

                if(k<cardsOnTable.getCardSet(z).size()){
                    //System.out.println("PATH: "+cardsOnTable.getCardSet(z).getCard(k).getImage());
                    vettoreImage.add(cardsOnTable.getCardSet(z).getCard(k).getImage());
                }
                else{
                    vettoreImage.add(null);
                }
                k++;
                numberOfCard++;
            }
        }

        for(int i=numberOfCard; i<(140);i++){
             vettoreImage.add(null);
        }
        System.out.println("[DraftLayout || Scala listener]  NumberOfCard sul tavolo="+numberOfCard);
        c.updateBoxOccupied(playerActions.getCardsOnTheTable().size()-1);
        c.DrawCard(100,100, vettore, vettoreImage);

    }

    public void refreshLineBaloon(int position, CardSet c){
        cardsCombinations.refreshLine(position, c);
    }

    public boolean isMyTurn(){
        return (myTurn==true);
    }

    public void setMyTurn(boolean t){
        myTurn=t;
    }

    public void setLabelTurn(boolean bool){
        if(bool){
            labelTurn.setIcon(new ImageIcon("src/small_cards/yes.png"));
        }else{
            labelTurn.setIcon(new ImageIcon("src/small_cards/no.png"));
        }
    }

    public void updateStatus(String value){
        labelStat.setText(" --- "+value+" ");
        labelStat.setForeground(Color.white);
    }

    public void resetBaloon(){
        
                    System.out.println("getComponent: "+popupMenu.getComponentCount());
                    switch(popupMenu.getComponentCount()){
                        case 2:
                                popupMenu.remove(1);
                                currentLine=0;
                                numberOfRows=1;
                                break;
                        case 3:
                                popupMenu.remove(1);
                                popupMenu.remove(1);
                                currentLine=0;
                                numberOfRows=1;
                                break;
                        case 4:
                                popupMenu.remove(1);
                                popupMenu.remove(1);
                                popupMenu.remove(1);
                                numberOfRows=1;
                                currentLine=0;
                                break;
                        case 5:
                                popupMenu.remove(1);
                                popupMenu.remove(1);
                                popupMenu.remove(1);
                                popupMenu.remove(1);
                                numberOfRows=1;
                                currentLine=0;
                                break;

                    }


                    cardsCombinations.removeAll();

    }
   

}





